//#version 120
precision mediump float;

uniform sampler2D uTexture;// 采样器
uniform int uChangeType;
uniform vec3 uChangeColor;
uniform int uHalf;
uniform float uHalfXY;
varying vec2 uCoord;
varying vec4 uPosition;
varying vec4 gPosition;

/**
*重置颜色数据，防止数据显示不正确
*/
void onModifyColor(vec4 color)
{
    color.r = max(min(color.r,1.0),0.0);
    color.g = max(min(color.g,1.0),0.0);
    color.b = max(min(color.b,1.0),0.0);
    color.a = max(min(color.a,1.0),0.0);
}


void main() {

    vec4 mColor = texture2D(uTexture,uCoord);
    if(uPosition.x > 0.0 || uHalf == 0 )
    {
        if(uChangeType == 1)
        {  //只取绿色       浮点算法
            float gray = (mColor.r * 0.3 + mColor.g * 0.59 + mColor.b * 0.114);
            gl_FragColor = vec4(gray,gray,gray,mColor.a);
        }
        else if(uChangeType == 2 )
        { //暖色   将要使用的色调 = 原来的纹素 + （要改变的效果的RGBA的值）
            vec4 mColorNum = mColor + vec4(0.1,0.1,0,0);
            onModifyColor(mColorNum);
            gl_FragColor = mColorNum;
        }
        else if(mChangeType == 3)
        { //冷色  美颜效果 ： 磨皮（模糊），美白（提升高度） ，红润（色调处理）
            vec4 mColorLenght = mColor + vec4(0.0,0.0,0.1,0.0);
            onModifyColor(mColorLenght);
            gl_FragColor = mColorLenght;

        }
        else if(mChangeType == 4)
        {//浮雕
            vec2 mTextSize = vec2(1500.0,1500.0);
            vec2 mUpTexture = vec2(uCoord.x -1.0 / mTextSize.x ,uCoord.y - 1.0/mTextSize.y);
            vec4 mNewTexture = texture2D(uTexture,mUpTexture);
            vec4 mDelTexture = mColor  - mNewTexture;
            gl_FragColor = mDelTexture + vec4(0.5,0.5,0.5,0.5);
        }
        else if(uChangeType == 5 )
        { // 颠倒

            gl_FragColor = texture2D(uTexture,vec2(1.0 - uCoord.x ,1.0 - uCoord.y));
        }
        else
        {//正常图片
            gl_FragColor = mColor;
        }
    }else
    {
        gl_FragColor = mColor;
    }
}
